package com.kool.kadmin.mqtt.controller;

import com.kool.kadmin.common.bean.PageListResult;
import com.kool.kadmin.common.bean.Result;
import com.kool.kadmin.common.util.ResultUtil;
import com.kool.kadmin.mqtt.request.AddTopicReq;
import com.kool.kadmin.mqtt.request.DeleteTopicReq;
import com.kool.kadmin.mqtt.request.GetTopicPageReq;
import com.kool.kadmin.mqtt.request.UpdateTopicReq;
import com.kool.kadmin.mqtt.service.TopicService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author luyu
 * @date 2021-04-21 14:50
 */
@RestController
public class TopicController {
    @Resource
    private TopicService topicService;

    /**
     * 分页查询主题
     *
     * @param request
     * @return
     */
    @PostMapping("/mqtt/getTopicPage")
    public PageListResult getTopicPage(@RequestBody @Valid GetTopicPageReq request) {
        return topicService.getTopicPage(request);
    }

    /**
     * 新增主题
     *
     * @param request
     * @return
     */
    @PostMapping("/mqtt/addTopic")
    public Result addTopic(@RequestBody @Valid AddTopicReq request) {
        topicService.addTopic(request);
        return ResultUtil.success();
    }

    /**
     * 更新主题
     *
     * @param request
     * @return
     */
    @PostMapping("/mqtt/updateTopic")
    public Result updateTopic(@RequestBody @Valid UpdateTopicReq request) {
        topicService.updateTopic(request);
        return ResultUtil.success();
    }

    /**
     * 删除主题
     *
     * @param request
     * @return
     */
    @PostMapping("/mqtt/deleteTopic")
    public Result deleteTopic(@RequestBody @Valid DeleteTopicReq request) {
        topicService.deleteTopic(request);
        return ResultUtil.success();
    }

}
